home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Tool Chest / Development Tools & Languages / Dylan Related / Marlais / Marlais 0.5.9-portable sources / alloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-15  |  3.7 KB  |  170 lines  |  [TEXT/ttxt]

  1. /*
  2.    alloc.c
  3.  
  4.    This software is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License as published by the Free Software Foundation; either
  7.    version 2 of the License, or (at your option) any later version.
  8.  
  9.    This software is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public
  15.    License along with this software; if not, write to the Free
  16.    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.    Original copyright notice follows:
  19.  
  20.    Copyright, 1993, Brent Benson.  All Rights Reserved.
  21.    0.4 & 0.5 Revisions Copyright 1994, Joseph N. Wilson.  All Rights Reserved.
  22.  
  23.    Permission to use, copy, and modify this software and its
  24.    documentation is hereby granted only under the following terms and
  25.    conditions.  Both the above copyright notice and this permission
  26.    notice must appear in all copies of the software, derivative works
  27.    or modified version, and both notices must appear in supporting
  28.    documentation.  Users of this software agree to the terms and
  29.    conditions set forth in this notice.
  30.  */
  31.  
  32. #include <string.h>
  33.  
  34. #include "alloc.h"
  35.  
  36. #include "env.h"
  37. #include "symbol.h"
  38. #include "gc.h"
  39. #include "error.h"
  40.  
  41. extern void GC_init (void);
  42.  
  43. /* function definitions */
  44.  
  45. void
  46. initialize_gc (void)
  47. {
  48.     GC_init ();
  49.     return;
  50. }
  51.  
  52. Object
  53. allocate_object (size_t size)
  54. {
  55.     Object obj;
  56.  
  57. #ifndef SMALL_OBJECTS
  58.     obj = (Object) GC_malloc (sizeof (struct object));
  59.  
  60. #else
  61.     obj = (Object) GC_malloc (size);
  62. #endif
  63.     if (!obj) {
  64.     fatal ("internal error: memory allocation failure.");
  65.     }
  66.     return (obj);
  67. }
  68.  
  69. struct frame *
  70. allocate_frame (void)
  71. {
  72.     struct frame *frame;
  73.  
  74.     frame = (struct frame *) GC_malloc (sizeof (struct frame));
  75.  
  76.     if (!frame) {
  77.     fatal ("internal error: memory allocation failure.");
  78.     }
  79.     return (frame);
  80. }
  81.  
  82. struct binding *
  83. allocate_binding (void)
  84. {
  85.     struct binding *binding;
  86.  
  87.     binding = (struct binding *) GC_malloc (sizeof (struct binding));
  88.  
  89.     if (!binding) {
  90.     fatal ("internal error: memory allocation failure.");
  91.     }
  92.     return (binding);
  93. }
  94.  
  95. struct module_binding *
  96. allocate_module_binding (void)
  97. {
  98.     struct module_binding *module_binding;
  99.  
  100.     module_binding =
  101.     (struct module_binding *) GC_malloc (sizeof (struct module_binding));
  102.  
  103.     if (!module_binding) {
  104.     fatal ("internal error: memory allocation failure.");
  105.     }
  106.     return (module_binding);
  107. }
  108.  
  109. struct symtab *
  110. allocate_symtab (void)
  111. {
  112.     struct symtab *entry;
  113.  
  114.     entry = (struct symtab *) GC_malloc (sizeof (struct symtab));
  115.  
  116.     if (!entry) {
  117.     fatal ("internal error: memory allocation failure.");
  118.     }
  119.     return (entry);
  120. }
  121.  
  122. void *
  123. checking_malloc (size_t size)
  124. {
  125.     void *ptr;
  126.  
  127.     ptr = (void *) GC_malloc (size);
  128.     if (!ptr) {
  129.     fatal ("internal error: memory allocation failure");
  130.     }
  131.     return (ptr);
  132. }
  133.  
  134. void *
  135. checking_realloc (void *ptr, size_t total_size)
  136. {
  137.     ptr = (void *) GC_realloc (ptr, total_size);
  138.     if (!ptr) {
  139.     fatal ("internal error: memory allocation failure");
  140.     }
  141.     return (ptr);
  142. }
  143.  
  144. char *
  145. checking_strdup (char *str)
  146. {
  147.     int size;
  148.     char *copied_str;
  149.  
  150.     size = strlen (str) + 1;
  151.     copied_str = (char *) GC_malloc_atomic (size);
  152.     if (!copied_str) {
  153.     fatal ("internal error: memory allocation failure");
  154.     }
  155.     strcpy (copied_str, str);
  156.     return (copied_str);
  157. }
  158.  
  159. char *
  160. allocate_string (size_t size)
  161. {
  162.     char *str;
  163.  
  164.     str = (char *) GC_malloc_atomic (size);
  165.     if (!str) {
  166.     fatal ("internal error: memory allocation failure.");
  167.     }
  168.     return (str);
  169. }
  170.